package com.tomato.displaySample;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class Camera_display extends Activity {

	Button camera_prevbutton,
	camera_sequanceButton,
	camera_controlSetButton,
	camera_quitButton;

	Spinner camera_numberOfControllerSpiner;

	ImageView camera_bottomDataValue1,
	camera_bottomDataValue2,
	camera_bottomDataValue3,
	camera_bottomDataValue4;

	TextView camera_bottomDataTitle1,
	camera_bottomDataTitle2,
	camera_bottomDataTitle3,
	camera_bottomDataTitle4;
	int currentPositionOfController;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.cameraview);
		// TODO Auto-generated method stub

		Intent intent = getIntent();
		int position = intent.getIntExtra("controllerNum3", 0);
		ArrayAdapter<String> controller = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
		controller.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		controller.add("選択してください。");
		controller.add("1	コントローラA");
		controller.add("3	コントローラB");
		controller.add("10	コントローラC");
		controller.add("30	テスト");
		controller.add("40	デモ用");
		controller.add("100	A");
		controller.add("128	B");

		camera_prevbutton = (Button)findViewById(R.id.Camera_prevbutton);
		camera_sequanceButton = (Button)findViewById(R.id.camera_sequanceButton);
		camera_controlSetButton = (Button)findViewById(R.id.camera_controlSetButton);
		camera_quitButton = (Button)findViewById(R.id.camera_quitButton);

		camera_numberOfControllerSpiner = (Spinner)findViewById(R.id.  camera_numberOfControllerSpiner);
		camera_numberOfControllerSpiner.setAdapter(controller);
		camera_numberOfControllerSpiner.setSelection(position, false);

		camera_bottomDataValue1 = (ImageView)findViewById(R.id.camera_bottomDataValue1);
		camera_bottomDataValue2 = (ImageView)findViewById(R.id.camera_bottomDataValue2);
		camera_bottomDataValue3 = (ImageView)findViewById(R.id.camera_bottomDataValue3);
		camera_bottomDataValue4 = (ImageView)findViewById(R.id.camera_bottomDataValue4);

		camera_bottomDataTitle1 = (TextView)findViewById(R.id.camera_bottomDataTitle1);
		camera_bottomDataTitle2 = (TextView)findViewById(R.id.camera_bottomDataTitle2);
		camera_bottomDataTitle3 = (TextView)findViewById(R.id.camera_bottomDataTitle3);
		camera_bottomDataTitle4 = (TextView)findViewById(R.id.camera_bottomDataTitle4);



		camera_bottomDataValue1.setImageResource(R.drawable.picture1);
		camera_bottomDataValue1.setOnClickListener(imageview_Listener);

		camera_bottomDataValue2.setImageResource(R.drawable.picture2);
		camera_bottomDataValue2.setOnClickListener(imageview_Listener);

		camera_bottomDataValue3.setImageResource(R.drawable.picture3);
		camera_bottomDataValue3.setOnClickListener(imageview_Listener);

		camera_bottomDataValue4.setImageResource(R.drawable.picture4);
		camera_bottomDataValue4.setOnClickListener(imageview_Listener);

		camera_prevbutton.setOnClickListener(button_Listener);
		camera_sequanceButton.setOnClickListener(button_Listener);
		camera_controlSetButton.setOnClickListener(button_Listener);
		camera_quitButton.setOnClickListener(button_Listener);
		camera_numberOfControllerSpiner.setOnItemSelectedListener(spiner_Listener);

	}
	private OnClickListener button_Listener=new OnClickListener() {
		@Override
		public void onClick(View v) {
			switch(v.getId()){
			case R.id.Camera_prevbutton:
			{	
				finish();
				break;
			}
			case R.id.camera_sequanceButton:
			{	
				Intent intent=new Intent(Camera_display.this, sequance_display.class);
				startActivity(intent);
				break;
			}
			case R.id.camera_controlSetButton:		
			{
				Intent intent=new Intent(Camera_display.this, Control_display.class);
				startActivity(intent);
				break;
			}
			case R.id.camera_quitButton:		
			{
				break;
			}
			}

		}
	};
	private OnClickListener imageview_Listener=new OnClickListener() {
		@Override
		public void onClick(View v) {
			Intent intent = new Intent(Camera_display.this,Camera_SpecView.class);
			switch(v.getId()){
			case R.id.camera_bottomDataValue1:
			{	
				intent.putExtra("state", 1);
				intent.putExtra("chtext", camera_bottomDataTitle1.getText());
				startActivity(intent);
				break;
			}
			case R.id.camera_bottomDataValue2:
			{
				intent.putExtra("state", 2);
				intent.putExtra("chtext", camera_bottomDataTitle2.getText());
				startActivity(intent);
				break;
			}
			case R.id.camera_bottomDataValue3:
			{
				intent.putExtra("state", 3);
				intent.putExtra("chtext", camera_bottomDataTitle3.getText());

				startActivity(intent);
				break;
			}
			case R.id.camera_bottomDataValue4:
			{

			}
			}

		}
	};
	private OnItemSelectedListener spiner_Listener = new OnItemSelectedListener() {

		@Override
		public void onItemSelected(AdapterView<?> parent,View view, int position, long id) {
			// TODO Auto-generated method stub
			currentPositionOfController = position;
			PopupMenu popupMenu = new PopupMenu(Camera_display.this, view);
			popupMenu.getMenuInflater().inflate(R.menu.motor_popup,popupMenu.getMenu());
			popupMenu.show();
			// ポップアップメニューのメニュー項目のクリック処理
			popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
				@Override
				public boolean onMenuItemClick(MenuItem item) {
					// 押されたメニュー項目名をToastで表示
					Toast.makeText(Camera_display.this, item.getTitle(),  Toast.LENGTH_SHORT).show();
					return true;
				}
			});
		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}


	};
}
